String clazzTpl({package}) => """
import 'dart:convert';
import 'redux_state.dart';
import 'package:redux/redux.dart';
import 'package:logging/logging.dart';
import 'package:$package/utils/print_util.dart';

final List<Middleware<ReduxState>> userMiddleware = [
  _asyncMiddleware,
  _loggingMiddleware,
];

/// 异步中间件
typedef AsyncAction<T> = dynamic Function(Store<T> store);

_asyncMiddleware<T>(Store<T> store, action, NextDispatcher next) {
  if (action is AsyncAction<T>) {
    return action.call(store);
  } else {
    return next.call(action);
  }
}

/// log中间件
final Logger _logger = Logger("$package Logger")
  ..onRecord
      .where((record) => record.loggerName == _logger.name)
      .listen(logPrint);

_loggingMiddleware(Store store, action, NextDispatcher next) {
  dynamic actionParameter;
  try {
    actionParameter = jsonEncode(action.data);
  } catch (e) {
    actionParameter = action.data;
  }
  logDebugPrint('[\${_logger.level.name}] \${_logger.name}: {\\n'
      '\\tActionType: \${action.type},\\n'
      '\\tActionData: \$actionParameter,\\n'
      '\\tTimestamp: \${DateTime.now()}\\n'
      '}');
  return next.call(action);
}
""";
